package com.coda.controller;

import com.coda.adminVo.fee.FeeKeyVo;
import com.coda.entity.FeeKey;
import com.coda.entity.FeeValue;
import com.coda.result.Result;
import com.coda.service.FeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/admin/fee")
@Api(tags = "公寓杂费管理")
public class FeeController {

    @Autowired
    private FeeService feeService;
    /**
     * 保存或更新杂费值
     */
    @PostMapping("/value/saveOrUpdate")
    @ApiOperation("保存或更新杂费值")
    public Result saveOrUpdateValue(@RequestBody FeeValue feeValue){
        feeService.saveOrUpdateValue(feeValue);
        return Result.ok();
    }
    /**
     *保存或更新杂费名称
     */
    @PostMapping("/key/saveOrUpdate")
    @ApiOperation("保存或更新杂费名称")
    public Result saveOrUpdateKey(@RequestBody FeeKey feeKey){
        feeService.saveOrUpdateKey(feeKey);
        return Result.ok();
    }
    /**
     * 查询全部杂费名称和杂费值列表
     */
    @GetMapping("/list")
    @ApiOperation("查询全部杂费名称和杂费值列表")
    public Result<List<FeeKeyVo>> list(){
        List<FeeKeyVo> feeKeyVos = feeService.list();
        return Result.ok(feeKeyVos);
    }
    /**
     * 根据id删除杂费值
     */
    @DeleteMapping("/value/deleteById")
    @ApiOperation("根据id删除杂费值")
    public Result deleteValueById(Long id){
        feeService.deleteValueById(id);
        return Result.ok();
    }
    /**
     * 根据id删除杂费名称
     */
    @DeleteMapping("/key/deleteById")
    @ApiOperation(value = "根据id删除杂费名称")
    public Result deleteKeyById(Long id){
        feeService.deleteKeyById(id);
        return Result.ok();
    }

}
